<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="author" content="wangbo">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      background-color: #363636;
    }

   div {
      width: 100px;
      height: 84px;
      background-image: url("./yihu.png");
      background-position: -22px -89px;
      background-repeat: no-repeat;
      /* animation: zhao 10s steps(5)  infinite; */
    }
  </style>
</head>

<body>

  <div style="position: absolute;left: 50%;top: 50%;" >

  </div>
  <script>
    let div = document.querySelector("div")
    window.onkeydown = function () {
      let left = Number.parseInt(div.style.left)
      let top = Number.parseInt(div.style.top)
      console.log(event.code)
      switch (event.code) {
        case "KeyU":
          div.style.backgroundPosition = "-22px -199px"
          break;
        case "KeyJ":
          div.style.backgroundPosition = "-22px -89px"
          break;
        case "KeyK":
          div.style.backgroundPosition = "-184px -86px"
          break;
        case "KeyL":
          div.style.backgroundPosition = "-391px -86px"
          break;
        case "KeyD":          
          left +=10;
          div.style.left = left+"px"
          break;
        case "KeyA":          
          left -=10;
          div.style.left = left+"px"
          break;
        case "KeyW":
          top -=10;
          div.style.top = top+"px"
          break;
        case "KeyS":
          top +=10;
          div.style.top = top+"px"
          break;
        default:
          break;
      }
    }
  </script>
</body>

</html>